package com.linkoog.devtools.metadata;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMember;
import com.linkoog.devtools.raw_index.PsiRawFileIndex;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

public abstract class Metadata<K extends PsiMember> implements Navigatable, PsiRawFileIndex.Item<K> {

    @Getter
    protected final String filePath;
    @Getter
    protected final int psiElementOffset;
    @Getter
    protected final String name;
    @Getter @Setter
    protected long timestamp;

    protected Metadata(String filePath, int psiElementOffset, String name) {
        this.filePath = filePath;
        this.psiElementOffset = psiElementOffset;
        this.name = name;
    }

    @NotNull
    public abstract K getPsiElement();


    @Override
    public void navigate(boolean requestFocus) {
        PsiMember psiMember = getPsiElement();
        if (psiMember != null){
            psiMember.navigate(requestFocus);
        }
    }

    @Override
    public boolean canNavigate() {
        PsiMember psiMember = getPsiElement();
        return psiMember != null && psiMember.canNavigate();
    }

    @Override
    public boolean canNavigateToSource() {
        PsiMember psiMember = getPsiElement();
        return psiMember != null && psiMember.canNavigateToSource();
    }

}
